package logic

import (
	"context"
	"novel/novelrpc/novelrpc"

	"novel/api/internal/svc"
	"novel/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type NovelUpdatesRequestLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewNovelUpdatesRequestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NovelUpdatesRequestLogic {
	return &NovelUpdatesRequestLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *NovelUpdatesRequestLogic) NovelUpdatesRequest(req *types.NovelUpdatesRequestRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	updates, err := l.svcCtx.NovelRpc.NovelUpdates(l.ctx, &novelrpc.NovelUpdatesRequest{
		Title:     req.Title,
		Brief:     req.Brief,
		HeadImage: req.HeadImage,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "修改成功",
		Data:    updates,
	}, nil
}
